import { reqBanner} from "../../request/api";
//初始值
const initState = {
  //初始化数据
  //轮播图
  banner:[]
  
};

//actionTypes
const types = {
  //修改数据 type
  CHANGE_BANNER: "MINE_CHANGE_BANNER",
};

//reducer 修改数据
const reducer = (state = initState, action) => {
  switch (action.type) {
    case types.CHANGE_BANNER:
      return {
        ...state,
        banner: action.banner,
      };
    default:
      return state;
  }
};
//actionCreators组件派发的动作
export const actions = {
  changeBanner: (banner) => ({ type: types.CHANGE_BANNER, banner}),
  
  //请求 异步操作
  //
  reqBanner: () => (dispatch, getState) => {
    reqBanner().then((res) => {
        if(res.data.code===200){
             //存信息
          dispatch(actions.changeBanner(res.data.list))
        }
    });
  },
  
};

//selectors导出数据
export const getBanner = state => state.mine.banner;

export default reducer;
